package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.SetFindPasswordModel;

public class SetFindPasswordActivity extends BaseActivity {
    private String email,setflag,phone;
    ImageView setfind_fh;
    EditText setfind_password,setfind_password1;
    Button setfind_btn;
    private String phem;
    ImageView setfind_iv1,setfind_iv2;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_set_find_password);
        email = getIntent().getStringExtra("email");
        phone = getIntent().getStringExtra("phone");
        setflag = getIntent().getStringExtra("setflag");
        setfind_fh = (ImageView)findViewById(R.id.setfind_fh);
        setfind_password = (EditText)findViewById(R.id.setfind_password);
        setfind_password1 = (EditText)findViewById(R.id.setfind_password1);
        setfind_btn = (Button)findViewById(R.id.setfind_btn);
        setfind_iv1 = (ImageView)findViewById(R.id.setfind_iv1);
        setfind_iv2 = (ImageView)findViewById(R.id.setfind_iv2);
        if (setflag.equals("1")){
            phem = phone;
        }
        else if (setflag.equals("2")){
            phem = email;
        }
       // Toast.makeText(SetFindPasswordActivity.this,setflag+phem,Toast.LENGTH_LONG).show();
    }

    @Override
    void initEvent() {
        setfind_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String password = setfind_password.getText().toString().trim();
                String password1 =setfind_password1.getText().toString().trim();

                if (!password.equals(password1)){
                    Toast.makeText(SetFindPasswordActivity.this,"两次密码不一致",Toast.LENGTH_LONG).show();
                }
                else if (password.equals("")||password1.equals("")){
                    Toast.makeText(SetFindPasswordActivity.this,"输入密码不能为空",Toast.LENGTH_LONG).show();
                }
                else {
                   // Toast.makeText(SetFindPasswordActivity.this,password+"--"+password1+"--"+setflag+phem,Toast.LENGTH_LONG).show();
                    SetFindPasswordModel setFindPasswordModel = new SetFindPasswordModel();
                    setFindPasswordModel.SetFindPassword(setflag,phem,password, new TListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            if (successBean.getSuccess().equals("1")){
                                Toast.makeText(SetFindPasswordActivity.this,"修改密码成功",Toast.LENGTH_LONG).show();
                                finish();
                            }
                            else {
                                Toast.makeText(SetFindPasswordActivity.this,"修改密码失败",Toast.LENGTH_LONG).show();
                            }
                        }
                        @Override
                        public void onFail(String msg) {
                            Toast.makeText(SetFindPasswordActivity.this,"修改密码失败1",Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        });

        setfind_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        setfind_iv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setPasswordVisibility();

            }
        });
        setfind_iv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setPasswordVisibility1();
            }
        });

    }
    private void setPasswordVisibility(){
        if (setfind_iv1.isSelected()) {
            setfind_iv1.setSelected(false);
            setfind_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        } else {
            setfind_iv1.setSelected(true);
            setfind_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        }
    }
    private void setPasswordVisibility1(){
        if (setfind_iv2.isSelected()) {
            setfind_iv2.setSelected(false);
            setfind_password1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        } else {
            setfind_iv2.setSelected(true);
            setfind_password1.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        }
    }

    @Override
    void initDate() {

    }
}
